package cn.xz.xy.adapter

import android.graphics.Color
import android.widget.ImageView
import android.widget.TextView
import androidx.core.content.ContextCompat
import cn.xz.xy.R
import cn.xz.xy.base.BaseApplication
import cn.xz.xy.bean.DeviceList
import cn.xz.xy.util.AppHelper
import cn.xz.xy.widgets.AutoScaleTextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder

/**
 * 设备列表适配器*/
class DeviceCAdapter : BaseQuickAdapter<DeviceList, BaseViewHolder>(R.layout.item_device_c) {

    override fun convert(holder: BaseViewHolder, item: DeviceList) {

        val tvDevice = holder.getView<AutoScaleTextView>(R.id.tv_device_c)
        tvDevice.post {
            tvDevice.text = item.name.toString()
        }

        val ivBg = holder.getView<TextView>(R.id.iv_bg)
        val ivDeviceItemImg = holder.getView<ImageView>(R.id.iv_device_item_img)
        //显示不同的图标
        when(item.deviceType){
            2,3,9,11,13-> {
                ivDeviceItemImg.setImageDrawable(ContextCompat.getDrawable(BaseApplication.getContext(),R.drawable.bg_device_item_zj1))
            }
            4,5,10->{
                ivDeviceItemImg.setImageDrawable(ContextCompat.getDrawable(BaseApplication.getContext(),R.drawable.bg_device_item_tyy1))
            }
            8->{
                if (item.name.toString().contains("LED")){
                    ivDeviceItemImg.setImageDrawable(ContextCompat.getDrawable(BaseApplication.getContext(),R.drawable.bg_device_item_led))
                }else if (item.name.toString().contains("拼接屏")){
                    ivDeviceItemImg.setImageDrawable(ContextCompat.getDrawable(BaseApplication.getContext(),R.drawable.bg_device_item_pjp1))
                }else{
                    ivDeviceItemImg.setImageDrawable(ContextCompat.getDrawable(BaseApplication.getContext(),R.drawable.bg_device_item_dsjj1))
                }
            }
            else->{
                if (item.name.toString().contains("LED")){
                    ivDeviceItemImg.setImageDrawable(ContextCompat.getDrawable(BaseApplication.getContext(),R.drawable.bg_device_item_led))
                }else if (item.name.toString().contains("拼接屏")){
                    ivDeviceItemImg.setImageDrawable(ContextCompat.getDrawable(BaseApplication.getContext(),R.drawable.bg_device_item_pjp1))
                }else{
                    ivDeviceItemImg.setImageDrawable(ContextCompat.getDrawable(BaseApplication.getContext(),R.drawable.bg_device_item_dsjj1))
                }            }
        }
        //是否已经开启
        ivDeviceItemImg.isSelected = item.opening
        val mD = AppHelper.getDrawable(R.mipmap.icon_device_bg1)
        val mC = Color.parseColor("#4B2D0D")
        ivBg.background = mD
        tvDevice.setTextColor(mC)
        if (item.opening){
            val mD1 = AppHelper.getDrawable(R.mipmap.icon_device_bg1_1)
            val mC1 = Color.parseColor("#FFFFFF")
            ivBg.background = mD1
            tvDevice.setTextColor(mC1)
        }
    }
}